/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package martino;

import java.util.HashMap;

/**
 *
 * @author sempere
 */
public class NoteManager {

    HashMap<String, Integer> notes;

    public NoteManager() {

        notes = new HashMap<String, Integer>();
        int noteNumber = 0;

        for (Integer i = -1; i < 9; i++) {
            notes.put("C" + i.toString(), noteNumber++);
            notes.put("C#" + i.toString(), noteNumber++);
            notes.put("D" + i.toString(), noteNumber++);
            notes.put("D#" + i.toString(), noteNumber++);
            notes.put("E" + i.toString(), noteNumber++);
            notes.put("F" + i.toString(), noteNumber++);
            notes.put("F#" + i.toString(), noteNumber++);
            notes.put("G" + i.toString(), noteNumber++);
            notes.put("G#" + i.toString(), noteNumber++);
            notes.put("A" + i.toString(), noteNumber++);
            notes.put("A#" + i.toString(), noteNumber++);
            notes.put("B" + i.toString(), noteNumber++);
	 
        }

        notes.put("C9", noteNumber++);
        notes.put("C#9", noteNumber++);
        notes.put("D9", noteNumber++);
        notes.put("D#9", noteNumber++);
        notes.put("E9", noteNumber++);
        notes.put("F9", noteNumber++);
        notes.put("F#9", noteNumber++);
        notes.put("G9", noteNumber++);

    }
    
    public int get(String nameNote){
        Integer num = notes.get(nameNote);

        if(num == null){

	    if(nameNote.substring(0,3).equals("DRUM")){
		num = Integer.parseInt(nameNote.substring(4,nameNote.length()));
	    } else {
		
		    nameNote = nameNote.replace("DO", "C");
		    nameNote = nameNote.replace("RE", "D");
		    nameNote = nameNote.replace("MI", "E");
		    nameNote = nameNote.replace("FA", "F");
		    nameNote = nameNote.replace("SOL", "G");
		    nameNote = nameNote.replace("LA", "A");
		    nameNote = nameNote.replace("SI", "B");
		    nameNote = nameNote.replace("TI", "B");
		
		    if(nameNote.contains("b")){
		        nameNote = nameNote.replace("Ab", "G#");
		        nameNote = nameNote.replace("Bb", "A#");
		        nameNote = nameNote.replace("Db", "C#");
		        nameNote = nameNote.replace("Eb", "D#");
		        nameNote = nameNote.replace("Gb", "F#");
		    } 

		    num = notes.get(nameNote);
		}
        } 
               
        return num;
    }
}
